package de.negativrekord.blockworld.geometry;

import cc.creativecomputing.graphics.CCDrawMode;
import cc.creativecomputing.graphics.CCGraphics;
import cc.creativecomputing.graphics.CCGraphics.CCPolygonMode;
import cc.creativecomputing.math.CCMath;
import cc.creativecomputing.math.CCVector2f;
import cc.creativecomputing.math.CCVector3f;

public class SectorStrip {

	/*
	 * #############
	 * # 0 # 1 # 2 #
	 * #############
	 *     # 3 #
	 *     #####
	 *     # 4 #
	 *     #####
	 *     # 5 #
	 *     #####
	 * 
	 * 
	 *     ##0##
	 *     3   1
	 *     ##2##
	 */    
	CCVector3f[] centers;
	CCVector3f[] normals;
	int size;
	Sector[] sectors = new Sector[6];
	int currentSector = 3;
	CCVector2f point = new CCVector2f(50,50);
	CCVector2f dir = new CCVector2f(1.3f,0.4f);
	

	
	public SectorStrip (int theSize) {
		
		size = theSize;
		centers = new CCVector3f[6];
		normals = new CCVector3f[6];
		
		// center normal offset
		sectors[0] = new Sector (new CCVector3f(-size/2,-size/2, size/2), new CCVector3f(1,0,0), new CCVector2f(-size,0), size);
		sectors[1] = new Sector (new CCVector3f(-size/2,-size/2, -size/2), new CCVector3f(0,0,1), new CCVector2f(0,0), size);
		sectors[2] = new Sector (new CCVector3f( size/2,-size/2,-size/2), new CCVector3f(-1,0,0), new CCVector2f(size,0), size);
		sectors[3] = new Sector (new CCVector3f(-size/2,-size/2,-size/2), new CCVector3f(0,1,0), new CCVector2f(0,-size), size);
		sectors[4] = new Sector (new CCVector3f(-size/2,-size/2, size/2), new CCVector3f(0,0,-1), new CCVector2f(0,-2*size), size);
		sectors[5] = new Sector (new CCVector3f(-size/2, size/2, size/2), new CCVector3f(0,-1,0), new CCVector2f(0,-3*size), size);
		
		sectors[0].setNeighbors(5,1,0,0);
		sectors[1].setNeighbors(5,2,0,0);
		sectors[2].setNeighbors(5,4,0,0);
		sectors[3].setNeighbors(1,2,0,0);
		sectors[4].setNeighbors(3,0,0,0);
		sectors[5].setNeighbors(4,2,0,0);
		
	}
	
	public void draw (CCGraphics g) {
		g.color(1f);
		g.polygonMode(CCPolygonMode.LINE);
		
		for (int i=0; i<sectors.length; i++) {
			g.polygonMode(CCPolygonMode.LINE);
			if (i==currentSector) g.polygonMode(CCPolygonMode.FILL);
			sectors[i].drawFlat(g);
		}
		g.pushMatrix();
		g.translate(350,100,0);
		for (int i=0; i<sectors.length; i++) {
			g.polygonMode(CCPolygonMode.LINE);
			sectors[i].draw3D(g);
		}
//		
//		g.color(0,1f,0,1f);
//		sectors[currentSector].drawPoint(g);
		g.popMatrix();
//		
		g.pointSize(5);
		g.color(1f,0,0);
		g.translate(sectors[currentSector].offset);
		g.point(point);
	}
	
	public void move () {
		point.add(dir);
		sectors[currentSector].wrapMove(point, dir);
	}
}
